<!-- src/components/charts/LineChart.vue -->
<template>
  <div ref="chartRef" style="width: 100%; height: 100%;"></div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import * as echarts from 'echarts'

const chartRef = ref()
let chart = null

const props = defineProps({
  options: {
    type: Object,
    required: true
  }
})

onMounted(() => {
  chart = echarts.init(chartRef.value)
  chart.setOption(props.options)
  
  // 响应式调整
  window.addEventListener('resize', handleResize)
})

onUnmounted(() => {
  window.removeEventListener('resize', handleResize)
  chart?.dispose()
})

const handleResize = () => {
  chart?.resize()
}
</script>